// 导入licia插件库
import { throttle } from 'miniprogram-licia'
Page({
  data: {
    visitorList: [],
    isEmpty: false,
  },
  onLoad() {
    // 获取访客列表
    this.getVisitorList()
    // 事件回调函数-节流
    this.getMoreVisitor = throttle(() => {
      if (!this.data.hasMore) return
      // console.log('11')
      this.getVisitorList(++this._current)
    }, 1000)
  },
  // getMoreVisitor() {
  // },
  // 访客列表接口
  async getVisitorList(current = 1, pageSize = 5) {
    const {
      pageTotal,
      code,
      data: { rows: visitorList },
    } = await wx.http.get('/visitor', { current, pageSize })
    if (code !== 10000) return wx.utils.toast('获取访客列表失败')
    this.setData({
      hasMore: pageTotal > current,
      isEmpty: visitorList.length === 0,
      visitorList: this.data.visitorList.concat(visitorList),
    })
    // 记录当前的页码
    this._current = current
  },
  goPassport() {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index',
    })
  },
})
